--
-- Author: ping.wang
-- Date: 2019-07-03 12:58:47
--
-- HandbookCombatPowerRender
--
local ClassRef = app.mvc.createListViewCell(...)

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.HandbookCombatPowerRender))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)
    self._ui.btn_go:addClickEventListener(function()
        --Resource跳转
        if self._conf then
            local p = string.split(GD:getConvertResource(self._conf.resource), "|")
            display.resourceGotoFeature({feature=p[1], param={p[3]}})
        end

    end)
    self:setContentSize( self._ui.Panel:getContentSize() )
    self:refresh()
end

--{type, percent, desc}
function ClassRef:refresh()
    if self._data then
        self:setVisible( true )

        local data = self._data
        local conf = GD:getDirectoryChallengePropById(data.type)
        if conf then
            self._conf = conf
            self._ui.icon:loadTexture(string.format(Res.HandbookChallengeIconPath,conf.propIcon))
            self._ui.name:setString(L(conf.propName))
            self._ui.text:setString(data.desc)
            self._ui.num:setString(string.format("%d%%",math.floor(data.percent)))
            if data.percent >= 100 then
                --self._ui.LoadingBar:loadTexture("", true)
                self._ui.LoadingBar:getVirtualRenderer():setColor(cc.c3b(255,186,0))
            else
                self._ui.LoadingBar:getVirtualRenderer():setColor(cc.c3b(79,184,255))
            end


            self._ui.LoadingBar:setPercent(data.percent)
        end
    else
        self:setVisible( false )
    end
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef
